$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});
function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : basePath+"/dorm/floor/addFloor",
		data : $('#addFloorForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(r) {
		    var data = JSON.parse(r);
			if (data.status == 1000) {
				parent.layer.msg(data.desc,function(){});
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.desc)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#addFloorForm").validate({
		rules : {
            floorId : {
				required : true
			},
            floorName : {
				required : true
			},
            floorAppend:{
			    required : true
            },
            floorStatus:{
			    required : true
            }
		},
		messages : {
            floorId : {
				required : icon + "请输入楼宇编号"
			},
            floorName : {
				required : icon + "请输入楼宇名称"
			},
            floorAppend : {
				required : icon + "请输入附加字段"
			},
            floorStatus : {
				required : icon + "请输入状态"
			}
		}
	})
}